<template>
  <div>
    <div class="DIS">
      <div class="left">
        <el-input style="margin-top:-15px;left: 400px" class="serchContent"  placeholder="请输入搜索内容" prefix-icon="el-icon-search"></el-input>
        <el-button  class="serch" type="primary"  icon="el-icon-search">搜索</el-button>
      </div>
    <div class="tableStu">
      <div>
      <el-table :data="tableData" height="100%" border class="table" >
        <el-table-column prop="sname" label="申请人" width="140">
        </el-table-column>
        <el-table-column prop="gender" label="性别" width="140">
        </el-table-column>
        <el-table-column prop="age" label="年龄" width="140">
        </el-table-column>
        <el-table-column prop="slevel" label="年级" width="140">
        </el-table-column>
        <el-table-column prop="name" label="申请课程" width="140">
        </el-table-column>
        <el-table-column prop="date_req" label="申请时间" width="160">
        </el-table-column>
        <el-table-column prop="allow" label="状态" width="100">
        </el-table-column>
        <el-table-column prop="date_resp" label="审批时间" width="180">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="140">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-check" circle  @click="setYes(scope.$index,scope.row)"></el-button>
            <el-button type="danger" icon="el-icon-close" circle @click="setNo(scope.$index,scope.row)">
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
  </div>
</div>
</template>

<script>
export default {
  methods: {
    getTime() {
      let date = new Date();
      let seperator1 = "-";
      let seperator2 = ":";
      //以下代码依次是获取当前时间的年月日时分秒
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let strDate = date.getDate();
      let minute = date.getMinutes();
      let hour = date.getHours();
      let second = date.getSeconds();
      //固定时间格式
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      if (hour >= 0 && hour <= 9) {
        hour = "0" + hour;
      }
      if (minute >= 0 && minute <= 9) {
        minute = "0" + minute;
      }
      if (second >= 0 && second <= 9) {
        second = "0" + second;
      }
      return year + seperator1 + month + seperator1 + strDate
        + " " + hour + seperator2 + minute + seperator2 + second;
    },




    action() {
      let _this = this
      this.$axios({
        method: 'GET',
        url: 'http://localhost/student_course/approveSelectCor',
      }).then(response => {
        _this.tableData=response.data
      })
    },

    setYes(index,row){
      let _this = this
      this.$axios({
        method: 'GET',
        url: 'http://localhost/student_course/setYes/'+row.sid+'/'+row.cid+'/'+_this.getTime(),
      }).then(response => {
        this.$message({
          type: 'success',
          message: '操作成功!',
        });
        _this.action();
      })

      _this.$axios({
        method:'POST',
        url:'http://localhost/student/saveMes',
        data:{
          sid:row.sid,
          cid:row.cid,
          allow:"已通过",
        }
      }).then(response => {

      })



      _this.$axios({
        method:"GET",
        url:"http://localhost/course/addOne/"+row.cid
      }).then(response => {

      })
    },

    setNo(index,row){
      let _this = this
      this.$axios({
        method: 'GET',
        url: 'http://localhost/student_course/setNo/'+row.sid+'/'+row.cid+'/'+_this.getTime(),
      }).then(response => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        _this.action();
      })
      _this.$axios({
        method:"GET",
        url:"http://localhost/course/subOne/"+row.cid
      }).then(response => {

      })

      _this.$axios({
        method:'POST',
        url:'http://localhost/student/saveMes',
        data:{
          sid:row.sid,
          cid:row.cid,
          allow:"未通过",
        }
      }).then(response => {

      })

    }
  },




  mounted() {
    this.action()
  },
  data() {
    return {
      tableData: [],
    }
  },


}
</script>

<style scoped>
.elInput {
  display: inline;
}

.tableStu {
  position: absolute;
  height: 80%;
  width: 85.8%
}

.DIS {
  display: flex;
  height: 50px;
  justify-content: space-between;
}

.left {
  display: flex;
  flex-direction: row;
  height: 40px;
}

.serch {
  position: relative;
  top:5px;
  left: 400px;
  margin-left: 20px;
}

.serchContent {
  position: relative;
  top:-40px;
  margin-left: 20px;
}

.add {
  position: relative;
  top: -55px;
  left: 730px;
}

.table{
  position: absolute;
  width: 100%;
  height: 100%;
}
</style>
